from sqlalchemy import Column, Integer, String, DateTime, Boolean
from sqlalchemy.orm import relationship
from datetime import datetime
from app.database import Base

class User(Base):
    __tablename__ = "users"

    id = Column(Integer, primary_key=True, index=True)
    username = Column(String(50), unique=True, index=True)
    email = Column(String(100), unique=True, index=True)
    phone = Column(String(20), unique=True, nullable=True)
    password = Column(String(100))
    name = Column(String(50), nullable=True)
    address = Column(String(200), nullable=True)
    created_at = Column(DateTime, default=datetime.utcnow)
    updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
    role = Column(String(20), default="user")
    is_active = Column(Boolean, nullable=False, default=True)

    # 关联关系
    orders = relationship("Order", back_populates="user")
    favorites = relationship("Favorite", back_populates="user") 